package com.migration.model.migration.scripts;

import com.migration.model.migration.AbstractMigrationScript;

/**
 * 文档表(risk_doc)迁移脚本
 */
public class A022_RiskDocMigrationScript extends AbstractMigrationScript {

    /**
     * 构造函数，初始化迁移配置
     */
    public A022_RiskDocMigrationScript() {
        super(
            "risk_doc",
            "文档数据迁移",
            "ra_document",
            "risk_doc",
            22
        );
    }

    /**
     * 生成迁移数据的SQL
     *
     * @return 迁移数据的SQL
     */
    @Override
    protected String generateMigrationSql() {
        return "INSERT INTO risk_doc (\n" +
                "  tenant_id,\n" +
                "  department_id,\n" +
                "  doc_type,\n" +
                "  file_name,\n" +
                "  upload_time,\n" +
                "  expire_time,\n" +
                "  expire_remind,\n" +
                "  remark,\n" +
                "  expire_status,\n" +
                "  create_time,\n" +
                "  create_by,\n" +
                "  update_time,\n" +
                "  update_by,\n" +
                "  is_del\n" +
                ")\n" +
                "SELECT\n" +
                "  1 as tenant_id,\n" +
                "  rd.tenant_id AS department_id,  -- 源表无此字段，默认填 0，可根据需要调整\n" +
                "  rd.type,\n" +
                "  rd.name,\n" +
                "  DATE_FORMAT(rd.create_time, '%Y-%m-%d %H:%i:%s'),\n" +
                "  DATE_FORMAT(rd.expire_date, '%Y-%m-%d'),\n" +
                "  COALESCE(rd.expire_remind_type, 1), -- 若为空默认提前一个月\n" +
                "  rd.remark,\n" +
                "  rd.status,\n" +
                "  DATE_FORMAT(rd.create_time, '%Y-%m-%d %H:%i:%s'),\n" +
                "  1,\n" +
                "  DATE_FORMAT(rd.update_time, '%Y-%m-%d %H:%i:%s'),\n" +
                "  1,\n" +
                "  rd.is_del\n" +
                "FROM risk_lunnan_test.ra_document rd;\n";
    }

}
